
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_SP_HENT_POST_NR]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[EBAS_SP_HENT_POST_NR]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [DBO].[EBAS_SP_HENT_POST_NR] 
	@session varchar(255),
	@postNr varchar(255) = '%',
	@by varchar(255) = '%'
WITH ENCRYPTION
AS
	DECLARE 
		@rettighed int,
		@antal int
	
	SET NOCOUNT ON

	CREATE TABLE #temp ( rett int )
	INSERT INTO #temp (rett)
	EXEC EBAS.DBO.EBAS_SP_SIKKERHED_VERIFICER_SESSION @session	

	SET @rettighed = (SELECT IsNull(max(rett),0) FROM #temp)
	
	IF 0 < @rettighed 
	BEGIN
		SET @antal = (SELECT COUNT(*) FROM EBAS_POST_NR)
		
		SELECT GUID, POST_NR, [BY], @antal AS ANTAL FROM EBAS_POST_NR
		WHERE POST_NR LIKE @postNr
		AND [BY] LIKE @by
		ORDER BY POST_NR
	END
	ELSE
		SELECT GUID, POST_NR, [BY], 0 AS ANTAL FROM EBAS_POST_NR
		WHERE GUID IS NULL
		ORDER BY POST_NR	
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
